define(['backbone'], function(Backbone) {
    var items = [{
        "id": "58",
        "title": "会计平台跨多组织生成凭证培训",
        "titletag": "碎片化培训",
        "content": "介绍要生成不同组织（账簿）的会计凭证，该如何进行会计平台配置",
        "goodcout": "0",
        "typeID": "10",
        "publisher":"周小琴",
        "contact":"0755-2348698",
        "version":"NC6.5 正式发布",
        "follow": false,
        "favorw": true,
        "favorwnum": 50,
        "time":"2016-02-09"
    }];

    var Model = Backbone.Model.extend({
        defaults: function() {
            return {
                'title': 'test'
            };
        },
        destroy:function(){
            this.trigger('destroy');
        }
    });


    var collections = Backbone.Collection.extend({
        model: Model,
        url: "./api/showcase",
        initialize:function(){
            this.reset(items);
        },
        fetch: function() {
            //this.addItem();
            //this.reset(items);
        },

        filter:function(_id){
            var data = [];
            for(var i=0; i < items.length; i++){
                if (items[i].typeID == _id) {
                    data.push(items[i]);
                }
            }
            this.reset(data);
        },

        fliterByThemeID: function(_id){
            var data = [];
            for(var i=0; i < items.length; i++){
                if (items[i].id == _id) {
                    data.push(items[i]);
                    break;
                }
            }
            this.reset(data);
        },

        addItem: function(){
            for (var i = 0; i < this.pageSize; i++) {
                var position = this.curPageIndex * this.pageSize + i;
                if(items.length > position){
                    this.add(new Model(items[position]));
                }else{
                    break;
                }
            }

        },

        curPageIndex: 0,
        pageSize: 10,
        getNextPage: function() {
            this.curPageIndex += 1;
            this.addItem();
        },
        hasNextPage: function() {
            return items.length/ this.pageSize > this.curPageIndex;
        },
        getFirstPage: function() {
            this.curPageIndex = 0;
            this.addItem();
        },
    });

    return collections;
});
